#include <windows.h>
#include "dxManager.h"
#include "sdManager.h"
#include "Draw.h"
#include "CardDataClass.h"
#include <ctime>

/////////////////////////////////////////////////////
#include "Player.h"

int endGame=0; //Message Window neccessity

int handCardNum = 0;
int fieldCardNum = 0;
/* explanation of phase numbers
0 - init phase		3 - p2 turn 1		6 - swap player		9 - p1 turn 2		12 - swap player	15 - p2 swap card
1 - p1 turn 1		4 - swap player		7 - p2 discard		10 - swap player	13 - p1 swap card	16 - end game
2 - swap player		5 - p1 discard		8 - swap player		11 - p2 turn 2		14 - swap player
*/
int phase = 0;
bool p1Turn = false;
bool firstTurn = true;
bool color = false;

Player p1, p2;

int color1 = -1, color2 = -1;
int p1Color1 = 0, p1Color2 = 0;
int p2Color1 = 0, p2Color2 = 0;

int score1 = 0, score2 = 0;
int p1Color = BLUE, p2Color = BLUE;
bool p1Swaped = false, p2Swaped = false;
bool oppCardCond = false;
////////////////////////////////////////////////////

HINSTANCE hInst;
HWND wndHandle;

bool initWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

//use for positioning the cursor
const int cursorWidth = 12, cursorHeight = 9;
const int handPosX[2] = { 625, 740 };
const int handPosY[3] = { 234, 354, 474 };
const int boardPosX[7] = { 235, 330, 427, 525, 282, 379, 473 };
const int boardPosY[2] = { 310, 441 };
//use for positioning the cards
const int cardWidth = 86, cardHeight = 120;
const int cardX[2] = { 555, 670 };
const int cardY[3] = { 234, 354, 474 };

int cursorMode = 0;
void initPowerCheck(int i, int& score1, int& score2);
void initPowerCheck2(int i, int& score1, int& score2);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	srand( (unsigned int)time(NULL) );

	if (!initWindow(hInstance))
		return false;

	dxManager* dxMgr = new dxManager();
	if( !dxMgr->init(wndHandle) )
		return 1;

	sdManager sdMgr = sdManager::getInstance();
	if( !sdMgr.initDS(wndHandle) )
		return 1;

	IDirect3DSurface9* bkgrd = dxMgr->getSurfaceFromBitmap("./BMP/Background.bmp");
	IDirect3DSurface9* cursor = dxMgr->getSurfaceFromBitmap("./BMP/Marked.bmp");

	//individual card colors
	IDirect3DSurface9* crdImages[8];
	IDirect3DSurface9* colorImages[6];
	LPDIRECT3DTEXTURE9 textureImage[2];
	textureImage[0] = NULL;

	if(!InitBMPs(dxMgr, crdImages, colorImages))
		return 1;

	//init the deck
	p1.InitDeck("Deck One.txt", dxMgr);
	p1.SuffleDeck();
	p1.DrawCardsFromDeckToHand();
	p2.InitDeck("Deck Two.txt", dxMgr);
	p2.SuffleDeck();
	p2.DrawCardsFromDeckToHand();

	InitColorVictory(p1, p2, color1, color2);

	RECT src, dest;
	src.top = dest.top = 0;
	src.left = dest.left = 0;
	src.right = dest.right = cursorWidth;
	src.bottom = dest.bottom = cursorHeight; 

	//play sound
	sdMgr.playSound();

	// Main message loop:
	// Enter the message loop
    MSG msg; 
    ZeroMemory( &msg, sizeof(msg) );
    while( msg.message != WM_QUIT )
    {
		// check for messages
		if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
        {
			TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
		// this is called when no messages are pending
		else
		{
			// call our render function
			dxMgr->beginRender();
			
			//draw cards and field
			if(phase%2 == 1)
			{
				dxMgr->blitToSurface(bkgrd, 0, 0);

				//draw card in hand and on field
				if(p1Turn)
				{
					DrawCards(dxMgr, p1, p2, cardWidth, cardHeight, 
						cardX, cardY, phase);

					if(!color)
						DrawPreview(dxMgr, p1, cursorMode, cardWidth, cardHeight,
							handCardNum, fieldCardNum);

					PrintVictoryColor(dxMgr, colorImages, p1Color1, p1Color2, p2Color1, p2Color2, color1, color2);
					dxMgr->PrintScore(score2, score1);
				}
				//draw for p2
				else
				{
					DrawCards(dxMgr, p2, p1, cardWidth, cardHeight,
						cardX, cardY, phase);

					if(!color)
						DrawPreview(dxMgr, p2, cursorMode, cardWidth, cardHeight,
							handCardNum, fieldCardNum);

					PrintVictoryColor(dxMgr,colorImages, p2Color1, p2Color2, p1Color1, p1Color2, color1, color2);
					dxMgr->PrintScore(score1, score2);
				}

				if(color)
					DrawColor(dxMgr, crdImages, cardWidth, cardHeight, cardX, cardY);

				// This is the Cursor to be Drawn on the hand
				dest.top = handPosY[handCardNum/2];
				dest.left = handPosX[handCardNum%2];
				dest.bottom = dest.top + cursorHeight;
				dest.right = dest.left + cursorWidth;
				dxMgr->blitToSurface(cursor, &src, &dest);

				//draw cursor on board but leave hand cursor as is
				if(cursorMode)
				{
					//if fieldCardNum <= 4 then the card will go to bottom half of field
					fieldCardNum < 4 ? dest.top = boardPosY[0] : dest.top = boardPosY[1];

					dest.left = boardPosX[fieldCardNum];
					dest.bottom = dest.top + cursorHeight;
					dest.right = dest.left + cursorWidth;
					dxMgr->blitToSurface(cursor, &src, &dest);
				}
			} 
			//print text
			else if(phase != 0)
			{
				//show all cards
				if(phase == 16)
				{
					dxMgr->blitToSurface(bkgrd, 0, 0);
					for(int i=0; i < 6; ++i)
						p1.DiscardHandCards(i);
					DrawCards(dxMgr, p1, p2, cardWidth, cardHeight, 
							cardX, cardY, phase);
					DrawCardOverlay(dxMgr, textureImage, p1, p2, p1Color, p2Color);
					CalculateVictoryColorPoint(p1, p2, p1Color1, p1Color2, p2Color1, p2Color2);
					PrintVictoryColor(dxMgr, colorImages, p1Color1, p1Color2, p2Color1, p2Color2, color1, color2);
					dxMgr->PrintScore(score2, score1);
					int winner=0;
					if (endGame==0)
					{
						if (score1 > score2)
						{
							winner = 1;
						}
						else if (score1==score2)
						{
							winner = 0;
						}
						else winner = 2;

						if (winner ==1)
						{
							MessageBox(wndHandle, "The Winner is Player 1 ", "", MB_OK);
							endGame=1;
						}
						else if (winner ==2)
						{
							MessageBox(wndHandle, "The Winner is Player 2", "", MB_OK);
							endGame=1;
						}						
						else if (winner == 0)
						{
							MessageBox(wndHandle, "Gratz on the DRAW!", "", MB_OK);
							endGame=1;
						}
						else
						{
						}
					}
				}
				else
				{
					dxMgr->printText(phase);
					if(phase == 4 || phase == 12)
					{
						score1 = p1.ShowFieldCard(0)->getPoints();
						score2 = p2.ShowFieldCard(0)->getPoints();
						initPowerCheck(0, score1, score2);
						initPowerCheck2(0, score1, score2);
						for(int i=1; i < 7; i++)
						{
							if(p1.HasFieldCard(i) != NULL)
							{
								score1 += p1.ShowFieldCard(i)->getPoints();
								initPowerCheck(i, score1, score2);								
							}
							if(p2.HasFieldCard(i) != NULL)
							{
								score2 += p2.ShowFieldCard(i)->getPoints();
								initPowerCheck2(i, score1, score2);
							}
						}
						CalculateVictoryColorPoint(p1, p2, p1Color1, p1Color2, p2Color1, p2Color2);
					}
				}
			}
			else
			{
				src.right = cardWidth;
				src.bottom = cardHeight;

				//display the color cards
				dest.top = 400;
				dest.left = 200;
				dest.right = dest.left + cardWidth;
				dest.bottom = dest.top + cardHeight;
				dxMgr->blitToSurface( p1.ShowLastCardInDeck()->GetCardImage(), &src, &dest);

				dest.left = 500;
				dest.right = dest.left + cardWidth;
				dest.bottom = dest.top + cardHeight;
				dxMgr->blitToSurface( p2.ShowLastCardInDeck()->GetCardImage(), &src, &dest);

				src.right = cursorWidth;
				src.bottom = cursorHeight;
			}

			//stop drawing and flip buffer
			dxMgr->endRender();

			//pass card for turn 2
			if(!firstTurn)
			{
				p1.DrawCardsFromDeckToHand();
				p2.DrawCardsFromDeckToHand();
				firstTurn = true;
			}
		}
    }//end message while

	// shutdown the directx manager
	dxMgr->shutdown();
	delete dxMgr;

	sdMgr.shutdownDS();

	//release all images
	bkgrd->Release();
	cursor->Release();
	for(int i=0; i < 8; ++i)
	{
		crdImages[i]->Release();
		i < 6 ? colorImages[i]->Release() : NULL;
	}

	if(textureImage[0])
	{
		textureImage[0]->Release();
		textureImage[1]->Release();
	}

	return (int) msg.wParam;
}

bool initWindow(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= 0;
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= NULL;
	wcex.lpszClassName	= "gToon";
	wcex.hIconSm		= 0;
	RegisterClassEx(&wcex);

	wndHandle = CreateWindow("gToon", 
							 "gToon", 
							 WS_OVERLAPPEDWINDOW,
							 CW_USEDEFAULT, 
							 CW_USEDEFAULT, 
							 800, 
							 600, 
							 NULL, 
							 NULL, 
							 hInstance, 
							 NULL);
   if (!wndHandle)
      return false;
   
   ShowWindow(wndHandle, SW_SHOW);
   UpdateWindow(wndHandle);

   return true;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message) 
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		//cursor Movement
		case WM_KEYDOWN:
			if(wParam == VK_ESCAPE)
			{
				PostQuitMessage(0);
				break;
			}
			//not accepting key presses after end game
			if(phase < 16)
				switch (wParam) 
				{ 
				// Process the LEFT ARROW key.
				case VK_LEFT:
					//hand mode cursor
					if (cursorMode == 0)
					{
						if(handCardNum % 2 == 1)
							handCardNum--;
					}
					//board mode cursor top
					else if (cursorMode == 1)
					{
						if(fieldCardNum > 0)
							fieldCardNum--;
					}
					//board mode cursor bottom
					else
						if(fieldCardNum > 4)
							fieldCardNum--;
					break;
				// Process the RIGHT ARROW key.
				case VK_RIGHT: 
					if (cursorMode == 0)
					{
						if(handCardNum % 2 != 1)
							handCardNum++;
					}
					//board mode cursor top
					else if (cursorMode == 1)
					{
						if(fieldCardNum < 3)
							fieldCardNum++;
					}
					//board mode cursor bottom
					else
						if(fieldCardNum < 6)
							fieldCardNum++;
					break;
				// Process the DOWN ARROW key.
				case VK_DOWN: 
					if (cursorMode == 0)
					{
						if(handCardNum < 4)
							handCardNum += 2;
					}
					break;
				//Process the UP ARROW key.
				case VK_UP: 
					if (cursorMode == 0)
					{
						if(handCardNum > 1)
							handCardNum -= 2;
					}
					break;
				 //Card selected
				case VK_SPACE:
					if(cursorMode == 0) //cursor in hand
					{
						//move cursor to top part of field
						if(phase%2 == 1 && phase < 8)
							cursorMode += 1;
						//move cursor to bottom part of field
						else if(phase > 8 && phase%2 == 1)
						{
							cursorMode += 2;
							if(fieldCardNum < 4)
								fieldCardNum = 4;
						}
					}
					//cursor is in field
					else
					{
						//move card from hand to field or vice versa
						if(p1Turn && phase%2 == 1)
							p1.SwapHandAndField(handCardNum, fieldCardNum);
						else if(phase%2 == 1) //p2 turn
							p2.SwapHandAndField(handCardNum, fieldCardNum);

						//move cursor back to hand
						cursorMode = 0;
					}

					//discarding phase
					if(phase == 5 || phase == 7)
					{
						if(p1Turn)
							p1.DiscardHandCards(handCardNum);
						else
							p2.DiscardHandCards(handCardNum);

						cursorMode = 0;
					}
					//swaping phase and color choose
					else if( phase == 13 || phase == 15)
					{
						if(p1Turn && !color)
						{
							if(p1.HasHandCard(handCardNum))
							{
								p1.SwapHandAndField(handCardNum, 6); //6 is the last card on the field
								p1Swaped = true;
								color = true;
							}
						}
						else if(!color)
						{
							if(p2.HasHandCard(handCardNum))
							{
								p2.SwapHandAndField(handCardNum, 6);
								p2Swaped = true;
								color = true;
							}
						}
						else
						{
							//set the color for the silver cards, add 2 becuase 0 and 1 are black and silver
							p1Turn ? p1Color = handCardNum + 2 : p2Color = handCardNum + 2;
							WndProc(hWnd, WM_KEYDOWN, VK_RETURN, lParam);
							break;
						}

						cursorMode = 0;
					}

					break;
				//move to next turn
				case VK_RETURN:
					//place card to field if player forgot to
					if(phase == 1 || phase == 3 || phase == 9 || phase == 11)
					{
						if(p1Turn)
							CardCheckForAmount(p1, phase);
						else
							CardCheckForAmount(p2, phase);
					}
					//switch to color choose phase
					else if( (phase == 13 || phase == 15) && !color)
					{
						color = true;
						break;
					}

					//move to change hotseat
					phase++;

					//change player turn
					if(phase%2 == 1)
						p1Turn ? p1Turn = false : p1Turn = true;

					//allow for new cards to be drawn from deck
					if(phase == 9)
						firstTurn = false;
						
					//reset cursor and stuff
					handCardNum = 0;
					fieldCardNum = 0;
					cursorMode = 0;
					color = false;

					break;
				}//end keydown switch
			break;
	}//end message switch
	return DefWindowProc(hWnd, message, wParam, lParam);
}

void initPowerCheck(int i, int& score1, int& score2)
{
	for (int j=0;j<7;j++)
	{
		if (p1.HasFieldCard(j)!=NULL)
		{
			if (p1.ShowFieldCard(i)->getID() == 14) //Blossom
			{
				if (p1.ShowFieldCard(j)->getID() == 20) //bubbles power
				{
					score1+=6;
				}
				else if (p1.ShowFieldCard(j)->getID() == 69) //Gangreen power
				{
					score1+=1;
				}
				else if (p1.ShowFieldCard(j)->getID() == 147) //townsville power
				{
					score1+=2;
				}
				else if (p1.ShowFieldCard(j)->getID() == 110) //Mojo Sandcastle Power
				{
					switch(j)
					{
						case 0:
							if (p1.ShowFieldCard(j+1)->getID() == 14 || p1.ShowFieldCard(j+4)->getID() == 14)
							{
								score1+=3;
							}
							break;
						case 1:
						case 2:
							if (p1.ShowFieldCard(j-1)->getID() ==14 || p1.ShowFieldCard(j+1)->getID() == 14 || 
								p1.ShowFieldCard(j+3)->getID() ==14 || p1.ShowFieldCard(j+4)->getID() == 14)
							{
								score1+=3;
							}
							break;
						case 3:
							if (p1.ShowFieldCard(j-1)->getID() ==14 || p1.ShowFieldCard(j+3)->getID() ==14)
							{
								score1+=3;
							}
							break;
						case 4:
							if (p1.ShowFieldCard(j+1)->getID() ==14 || p1.ShowFieldCard(j-4)->getID() ==14 ||
								p1.ShowFieldCard(j-3)->getID() ==14)
							{
								score1+=3;
							}
							break;
						case 5:
							if (p1.ShowFieldCard(j-1)->getID() ==14 || p1.ShowFieldCard(j+1)->getID() ==14 ||
								p1.ShowFieldCard(j-3)->getID() ==14 || p1.ShowFieldCard(j-4)->getID() ==14)
							{
								score1+=3;
							}
							break;
						case 6:
							if (p1.ShowFieldCard(j-1)->getID() ==14 || p1.ShowFieldCard(j-3)->getID() ==14 ||
								p1.ShowFieldCard(j-4)->getID() ==14)
							{
								score1+=3;
							}
							break;
					}
				}
			}
			//else if (p1.ShowFieldCard(i)->getID() == 11) //Batman
			//{
			//	if (p1.ShowFieldCard(j)->getID() ==11)
			//	{
			//		if (p2.ShowFieldCard(i)->getFeatures() != 'Hero')
			//		{
			//			score2-=5;
			//		}
			//	}
			//}
			else if (p1.ShowFieldCard(i)->getID() == 27) //Buttercup
			{
				if (p1.ShowFieldCard(j)->getID() == 20) // bubbles power
				{
					score1+=6;
				}
				else if (p1.ShowFieldCard(j)->getID() == 147) //townsville power
				{
					score1+=2;
				}
				else if (p1.ShowFieldCard(j)->getID() == 110) //mojoSandCastle power
				{
					switch(j)
					{
						case 0:
							if (p1.ShowFieldCard(j+1)->getID() == 27 || p1.ShowFieldCard(j+4)->getID() == 27)
							{
								score1+=3;
							}
							break;
						case 1:
						case 2:
							if (p1.ShowFieldCard(j-1)->getID() ==27 || p1.ShowFieldCard(j+1)->getID() == 27 || 
								p1.ShowFieldCard(j+3)->getID() ==27 ||	p1.ShowFieldCard(j+4)->getID() == 27)
							{
								score1+=3;
							}
							break;
						case 3:
							if (p1.ShowFieldCard(j-1)->getID() ==27 || p1.ShowFieldCard(j+3)->getID() ==27)
							{
								score1+=3;
							}
							break;
						case 4:
							if (p1.ShowFieldCard(j+1)->getID() ==27 || p1.ShowFieldCard(j-4)->getID() ==27 ||
								p1.ShowFieldCard(j-3)->getID() ==27)
							{
								score1+=3;
							}
							break;
						case 5:
							if (p1.ShowFieldCard(j-1)->getID() ==27 || p1.ShowFieldCard(j+1)->getID() ==27 ||
								p1.ShowFieldCard(j-3)->getID() ==27 || p1.ShowFieldCard(j-4)->getID() ==27)
							{
								score1+=3;
							}
							break;
						case 6:
							if (p1.ShowFieldCard(j-1)->getID() ==27 || p1.ShowFieldCard(j-3)->getID() ==27 ||
								p1.ShowFieldCard(j-4)->getID() ==27)
							{
								score1+=3;
							}
							break;
					}
				}
				else if (p1.ShowFieldCard(j)->getID() == 69) //Gangreen power
				{
					switch (j)
					{
						case 0:
							if (p1.ShowFieldCard(j+1)->getID() == 27 || p1.ShowFieldCard(j+4)->getID() == 27)
							{
								score1+=8;
							}
							break;
						case 1:
						case 2:
							if (p1.ShowFieldCard(j-1)->getID() ==27 || p1.ShowFieldCard(j+1)->getID() == 27 || 
								p1.ShowFieldCard(j+3)->getID() ==27 ||	p1.ShowFieldCard(j+4)->getID() == 27)
							{
								score1+=8;
							}
							break;
						case 3:
							if (p1.ShowFieldCard(j-1)->getID() ==27 || p1.ShowFieldCard(j+3)->getID() ==27)
							{
								score1+=8;
							}
							break;
						case 4:
							if (p1.ShowFieldCard(j+1)->getID() ==27 || p1.ShowFieldCard(j-4)->getID() ==27 ||
								p1.ShowFieldCard(j-3)->getID() ==27)
							{
								score1+=8;
							}
							break;
						case 5:
							if (p1.ShowFieldCard(j-1)->getID() ==27 || p1.ShowFieldCard(j+1)->getID() ==27 ||
								p1.ShowFieldCard(j-3)->getID() ==27 || p1.ShowFieldCard(j-4)->getID() ==27)
							{
								score1+=8;
							}
							break;
						case 6:
							if (p1.ShowFieldCard(j-1)->getID() ==27 || p1.ShowFieldCard(j-3)->getID() ==27 ||
								p1.ShowFieldCard(j-4)->getID() ==27)
							{
								score1+=8;
							}
							break;
					}
				}
			}
			else if (p1.ShowFieldCard(i)->getID() == 20) //bubbles
			{
				if (p1.ShowFieldCard(j)->getID() == 147) //townsville power
				{
					score1+=2;
				}
				else if (p1.ShowFieldCard(j)->getID() == 69) //Gangreen power
				{
					score1+=1;
				}
				else if (p1.ShowFieldCard(j)->getID() == 119) //Octi power
				{
					score1+=5;
				}
				else if (p1.ShowFieldCard(j)->getID() == 110) //mojoSandCastle power
				{

					switch(j)
						{
							case 0:
								if (p1.ShowFieldCard(j+1)->getID() == 20 || p1.ShowFieldCard(j+4)->getID() == 20)
								{
									score1+=3;
								}
								break;
							case 1:
							case 2:
								if (p1.ShowFieldCard(j-1)->getID() ==20 || p1.ShowFieldCard(j+1)->getID() == 20 || 
									p1.ShowFieldCard(j+3)->getID() ==20 ||	p1.ShowFieldCard(j+4)->getID() == 20)
								{
									score1+=3;
								}
								break;
							case 3:
								if (p1.ShowFieldCard(j-1)->getID() ==20 || p1.ShowFieldCard(j+3)->getID() ==20)
								{
									score1+=3;
								}
								break;
							case 4:
								if (p1.ShowFieldCard(j+1)->getID() ==20 || p1.ShowFieldCard(j-4)->getID() ==20 ||
									p1.ShowFieldCard(j-3)->getID() ==20)
								{
									score1+=3;
								}
								break;
							case 5:
								if (p1.ShowFieldCard(j-1)->getID() ==20 || p1.ShowFieldCard(j+1)->getID() ==20 ||
									p1.ShowFieldCard(j-3)->getID() ==20 || p1.ShowFieldCard(j-4)->getID() ==20)
								{
									score1+=3;
								}
								break;
							case 6:
								if (p1.ShowFieldCard(j-1)->getID() ==20 || p1.ShowFieldCard(j-3)->getID() ==20 ||
									p1.ShowFieldCard(j-4)->getID() ==20)
								{
									score1+=3;
								}
								break;
						}
				}
			}
			else if (p1.ShowFieldCard(i)->getID() == 123) // Professor Utonium
			{
				if (p1.ShowFieldCard(j)->getID() == 115) //MS.Keene Power
				{
					switch(j)
						{
							case 0:
								if (p1.ShowFieldCard(j+1)->getID() == 123 || p1.ShowFieldCard(j+4)->getID() == 123)
								{
									score1+=5;
								}
								break;
							case 1:
							case 2:
								if (p1.ShowFieldCard(j-1)->getID() ==123 || p1.ShowFieldCard(j+1)->getID() == 123 || 
									p1.ShowFieldCard(j+3)->getID() ==123 ||	p1.ShowFieldCard(j+4)->getID() == 123)
								{
									score1+=5;
								}
								break;
							case 3:
								if (p1.ShowFieldCard(j-1)->getID() ==123 || p1.ShowFieldCard(j+3)->getID() ==123)
								{
									score1+=5;
								}
								break;
							case 4:
								if (p1.ShowFieldCard(j+1)->getID() ==123 || p1.ShowFieldCard(j-4)->getID() ==123 ||
									p1.ShowFieldCard(j-3)->getID() ==123)
								{
									score1+=5;
								}
								break;
							case 5:
								if (p1.ShowFieldCard(j-1)->getID() ==123 || p1.ShowFieldCard(j+1)->getID() ==123 ||
									p1.ShowFieldCard(j-3)->getID() ==123 || p1.ShowFieldCard(j-4)->getID() ==123)
								{
									score1+=5;
								}
								break;
							case 6:
								if (p1.ShowFieldCard(j-1)->getID() ==123 || p1.ShowFieldCard(j-3)->getID() ==123||
									p1.ShowFieldCard(j-4)->getID() ==123)
								{
									score1+=5;
								}
								break;
						}
				}
			}
			else if (p1.ShowFieldCard(i)->getID() == 115) //MS.Keane
			{
				if (p1.ShowFieldCard(j)->getColor() == 0x10) //Checking for Purple
				{
					score1+=3;
				}
			}
			else if (p1.ShowFieldCard(i)->getID() == 110)//mojoSandcastle
			{
				if (p1.ShowFieldCard(j)->getID() == 147) //townsville power
				{
					score1+=2;
				}
			}
			else if (p1.ShowFieldCard(i)->getID() == 142) //simion
			{
				if (p1.ShowFieldCard(j)->getID() == 110)
				{
					score1+=6;
				}
			}
		}
	}
}

void initPowerCheck2(int i, int& score1, int& score2)
{
	for (int j=0;j<7;j++)
	{
		if (p2.HasFieldCard(j)!=NULL)
		{
			if (p2.ShowFieldCard(i)->getID() == 6) //Aquaman Power
			{
				if (p2.ShowFieldCard(j)->getColor()== 0x8)
				{
					score2+=3;
				}
			}
			else if (p2.ShowFieldCard(i)->getID() == 56)//ED in Play
			{
				if (p2.ShowFieldCard(j)->getID() == 47) //Dexter Dimwit
				{
					score2+=3;
				}
				else if (p2.ShowFieldCard(j)->getID() ==127) //rolf Power
				{
					score2+=3;
				}
				else if (p2.ShowFieldCard(j)->getID() == 86) //jawBreaker
				{
					switch(j)
						{
							case 0:
								if (p2.ShowFieldCard(j+1)->getID() == 56 || p2.ShowFieldCard(j+4)->getID() == 56)
								{
									score2+=10;
								}
								break;
							case 1:
							case 2:
								if (p2.ShowFieldCard(j-1)->getID() ==56 || p2.ShowFieldCard(j+1)->getID() == 56|| 
									p2.ShowFieldCard(j+3)->getID() ==56 || p2.ShowFieldCard(j+4)->getID() == 56)
								{
									score2+=10;
								}
								break;
							case 3:
								if (p2.ShowFieldCard(j-1)->getID() ==56 || p2.ShowFieldCard(j+3)->getID() ==56)
								{
									score2+=10;
								}
								break;
							case 4:
								if (p2.ShowFieldCard(j+1)->getID() ==56 || p2.ShowFieldCard(j-4)->getID() ==56 ||
									p2.ShowFieldCard(j-3)->getID() ==56)
								{
									score2+=10;
								}
								break;
							case 5:
								if (p2.ShowFieldCard(j-1)->getID() ==56 || p2.ShowFieldCard(j+1)->getID() ==56 ||
									p2.ShowFieldCard(j-3)->getID() ==56 || p2.ShowFieldCard(j-4)->getID() ==56)
								{
									score2+=10;
								}
								break;
							case 6:
								if (p2.ShowFieldCard(j-1)->getID() ==56 || p2.ShowFieldCard(j-3)->getID() ==56||
									p2.ShowFieldCard(j-4)->getID() ==56)
								{
									score2+=10;
								}
								break;
						}
				}
			}
			else if (p2.ShowFieldCard(i)->getID() == 54) //EDD
			{
				if (p2.ShowFieldCard(j)->getID() == 47) //Dexter Dimwit power
				{
					score2+=3;
				}
				else if (p2.ShowFieldCard(j)->getID() ==127) //rolf Power
				{
					score2+=3;
				}
				else if (p2.ShowFieldCard(j)->getID() ==56) //ed power
				{
					score2+=4;
				}
				else if (p2.ShowFieldCard(j)->getID() ==49) //prop Dexter exo jock power
				{
					score2+=2;
				}
				else if (p2.ShowFieldCard(j)->getID() == 86) //jawBreaker
				{
					score2+=2; //Jawbreaker is a prop
					switch(j)
						{
							case 0:
								if (p2.ShowFieldCard(j+1)->getID() == 54 || p2.ShowFieldCard(j+4)->getID() == 54)
								{
									score2+=12;
								}
								break;
							case 1:
							case 2:
								if (p2.ShowFieldCard(j-1)->getID() ==54 || p2.ShowFieldCard(j+1)->getID() == 54|| 
									p2.ShowFieldCard(j+3)->getID() ==54 || p2.ShowFieldCard(j+4)->getID() == 54)
								{
									score2+=12;
								}
								break;
							case 3:
								if (p2.ShowFieldCard(j-1)->getID() ==54 || p2.ShowFieldCard(j+3)->getID() ==54)
								{
									score2+=12;
								}
								break;
							case 4:
								if (p2.ShowFieldCard(j+1)->getID() ==54 || p2.ShowFieldCard(j-4)->getID() ==54 ||
									p2.ShowFieldCard(j-3)->getID() ==54)
								{
									score2+=12;
								}
								break;
							case 5:
								if (p2.ShowFieldCard(j-1)->getID() ==54 || p2.ShowFieldCard(j+1)->getID() ==54 ||
									p2.ShowFieldCard(j-3)->getID() ==54 || p2.ShowFieldCard(j-4)->getID() ==54)
								{
									score2+=12;
								}
								break;
							case 6:
								if (p2.ShowFieldCard(j-1)->getID() ==54 || p2.ShowFieldCard(j-3)->getID() ==54||
									p2.ShowFieldCard(j-4)->getID() ==54)
								{
									score2+=12;
								}
								break;
						}
				}
			}
			else if (p2.ShowFieldCard(i)->getID() == 55) //Eddy
			{
				if (p2.ShowFieldCard(j)->getID() == 47) //Dexter Dimwit
				{
					score2+=3;
				}
				else if (p2.ShowFieldCard(j)->getID() ==127) //rolf Power
				{
					score2+=3;
				}	
				else if (p2.ShowFieldCard(j)->getID() ==56) //ed power
				{
					score2+=4;
				}
				else if (p2.ShowFieldCard(j)->getID() == 86) //jawBreaker
				{
					switch(j)
						{
							case 0:
								if (p2.ShowFieldCard(j+1)->getID() == 55 || p2.ShowFieldCard(j+4)->getID() == 55)
								{
									score2+=8;
								}
								break;
							case 1:
							case 2:
								if (p2.ShowFieldCard(j-1)->getID() ==55 || p2.ShowFieldCard(j+1)->getID() == 55|| 
									p2.ShowFieldCard(j+3)->getID() ==55 || p2.ShowFieldCard(j+4)->getID() == 55)
								{
									score2+=8;
								}
								break;
							case 3:
								if (p2.ShowFieldCard(j-1)->getID() ==55 || p2.ShowFieldCard(j+3)->getID() ==55)
								{
									score2+=8;
								}
								break;
							case 4:
								if (p2.ShowFieldCard(j+1)->getID() ==55 || p2.ShowFieldCard(j-4)->getID() ==55 ||
									p2.ShowFieldCard(j-3)->getID() ==55)
								{
									score2+=8;
								}
								break;
							case 5:
								if (p2.ShowFieldCard(j-1)->getID() ==55 || p2.ShowFieldCard(j+1)->getID() ==55 ||
									p2.ShowFieldCard(j-3)->getID() ==55 || p2.ShowFieldCard(j-4)->getID() ==55)
								{
									score2+=8;
								}
								break;
							case 6:
								if (p2.ShowFieldCard(j-1)->getID() ==55 || p2.ShowFieldCard(j-3)->getID() ==55||
									p2.ShowFieldCard(j-4)->getID() ==55)
								{
									score2+=8;
								}
								break;
						}
				}
			}
		}
	}

}
